/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-1-15 下午12:10 Created by lyyang
 */
package com.jade.bss.business.activity.impl;

import java.util.List;
import javax.ejb.TransactionAttribute;
import javax.inject.Inject;
import javax.inject.Named;

import com.jade.bss.business.activity.Activity;
import com.jade.bss.business.activity.ActivityDao;
import com.jade.bss.business.activity.ActivityManager;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.criterion.Restrictions;
import com.jade.framework.base.util.PagingList;
import org.springframework.transaction.annotation.Transactional;

/**
 * 活动管理器实现
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-1-15 下午12:10
 */
@Named ("bss_activityManager")
public class ActivityManagerImpl implements ActivityManager
{
    private ActivityDao activityDao;

    @Inject
    public void setActivityDao(@Named ("bss_activityDao") ActivityDao activityDao)
    {
        this.activityDao = activityDao;
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void add(Activity activity)
    {
        activityDao.add(activity);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void update(Activity activity)
    {
        activityDao.update(activity);
    }

    public Activity get(long id)
    {
        return activityDao.get(id);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void remove(long... ids)
    {
        for (long id : ids) {
            activityDao.remove(id);
        }
    }

    public List<Activity> list(String ownerType, String ownerId, Criteria criteria)
    {
        if (criteria == null) {
            criteria = new Criteria(-1, -1);
        }
        criteria.add(Restrictions.eq("ownerId", ownerId));
        criteria.add(Restrictions.eq("ownerType", ownerType));
        return activityDao.list(criteria);
    }

    public PagingList<Activity> query(String ownerType, String ownerId, Criteria criteria)
    {

        if (criteria == null) {
            criteria = new Criteria(-1, -1);
        }
        criteria.add(Restrictions.eq("ownerId", ownerId));
        criteria.add(Restrictions.eq("ownerType", ownerType));
        return activityDao.query(criteria);
    }

    public PagingList<Activity> query(Criteria criteria)
    {
        return activityDao.query(criteria);
    }

    public List<Activity> list(Criteria criteria)
    {
        if (criteria == null) {
            criteria = new Criteria(-1, -1);
        }
        return activityDao.list(criteria);
    }
}
